<?php

class index extends Controller {
	public function html() {
		$mUser = new User_model();
		$currUser = $mUser->currUser();
		if(!$currUser) header('Location: /user/login?backurl=/user/order/');
		
		$page = $this->get('page', 'int', 1);
		$size = 10;
		$mOrder = new Order_model();
		$params = array('uid' => $currUser['uid']);
		$data['order'] = $mOrder->page($page, $size, $params);
		
		$product = array();
		foreach ($data['order']['data'] as $key => $value) {
			$product[] = $value['product_id'];
			$ticket[] = $value['ticket_id'];
		}
		//获取景点信息
		$mProduct = new Product_model();
		$params  = array('id in' => $product);
		$productInfo = $mProduct->productsInfo($params);
		
		$mTicket = new Ticket_model();
		$params  = array('tid in' => $ticket);
		$ticketInfo = $mTicket->ticket($params);
		foreach ($data['order']['data'] as $key => $value) {
			$data['order']['data'][$key]['product'] = $productInfo[$value['product_id']];
			$data['order']['data'][$key]['ticket'] = $ticketInfo[$value['ticket_id']];
		}
		$tpl = 'user/order/index.html';
		$this->display($data, $tpl);
	}
}